/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package alarmactioneventhandler;

/**
 *
 * @author chris
 */
public class AlarmClock {

    private AlarmActionEventHandler alarm;
    private int nrings; // define in the constructor

    public AlarmClock(AlarmActionEventHandler alarm, int nrings) {
        this.alarm = alarm;
        this.nrings = nrings;
    }

    public void onAlarm(AlarmEventArgs e) {
        if (alarm != null) {
//Invoke the event handler.
            alarm.alarmActionPerformed(e);
        }
    }
// event handling method
    public void Start() {
        for (;;) {
            nrings--;
            if (nrings < 0) {
                break;
            } else {
                AlarmEventArgs e = new AlarmEventArgs(nrings);
                onAlarm(e);
            }
        }
    }
}
